package com.yanqu.road.server.manger.activity.peakstronghold;

import com.yanqu.road.entity.activity.peakstronghold.PeakStrongholdUploadMarkData;
import com.yanqu.road.entity.activity.peakstronghold.config.ePeakStrongholdStageType;
import com.yanqu.road.logic.bussiness.activity.PeakStrongholdActivityBusiness;
import com.yanqu.road.server.manger.union.CrossUnionMgr;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class PeakStrongholdGroup {
    private int activityId;
    private Map<Integer, PeakStrongholdUploadMarkData> uploadMarkDataMap = new ConcurrentHashMap<>();

    public PeakStrongholdGroup(int activityId) {
        this.activityId = activityId;
    }

    public int getActivityId() {
        return activityId;
    }

    public void setUploadMarkDataMap(Map<Integer, PeakStrongholdUploadMarkData> uploadMarkDataMap) {
        this.uploadMarkDataMap = uploadMarkDataMap;
    }

    public Map<Integer, PeakStrongholdUploadMarkData> getUploadMarkDataMap() {
        return uploadMarkDataMap;
    }

    public PeakStrongholdUploadMarkData getUploadMarkData(int unionGroup) {
        PeakStrongholdUploadMarkData markData = uploadMarkDataMap.get(unionGroup);
        if (markData == null) {
            synchronized (uploadMarkDataMap){
                markData = uploadMarkDataMap.get(unionGroup);
                if (markData == null) {
                    markData = new PeakStrongholdUploadMarkData(activityId, unionGroup);
                    uploadMarkDataMap.put(unionGroup, markData);
                }
            }
        }

        return markData;
    }

    public boolean save() {
        for (PeakStrongholdUploadMarkData uploadMarkData : uploadMarkDataMap.values()) {
            if (uploadMarkData.isInsertOption()) {
                PeakStrongholdActivityBusiness.addPeakStrongholdUploadMarkData(uploadMarkData);
            } else if (uploadMarkData.isUpdateOption()) {
                PeakStrongholdActivityBusiness.updatePeakStrongholdUploadMarkData(uploadMarkData);
            }
        }
        return true;
    }
}
